package ru.spb.osll.myfit.server.execute;

import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertEquals;

import org.easymock.EasyMockSupport;
import org.junit.Before;
import org.junit.Test;

import ru.spb.osll.myfit.fixtures.base.DummyOneLineFixture;
import ru.spb.osll.myfit.fixtures.base.OneLineFixtureUtilsTest;
import fit.FixtureLoader;
import fit.Parse;

public class MyFitFixtureRunnerTest extends EasyMockSupport {
	private static final String HTML = "<table border=\"1\" cellspacing=\"0\">\n"
			+ "<tr><td class=\"pass\">dummy one line</td>\n"
			+ "<td>OK</td>\n</tr>\n</table>\n"
			+ "<br/><table border=\"1\" cellspacing=\"0\">\n"
			+ "<tr><td class=\"pass\">dummy one line</td>\n"
			+ "<td>OK</td>\n</tr>\n</table>\n";
	static final String SYSTEM_LINE_SEPARATOR = System
			.getProperty("line.separator");
	
	private FixtureLoader fixtureLoader;
	private MyFitFixtureRunner runner;
	private MyFitFixtureListener listener;

	@Before
	public void setUp() {
		fixtureLoader = createStrictMock(FixtureLoader.class);
		listener = new MyFitFixtureListener();
		runner = new MyFitFixtureRunner(fixtureLoader, listener);
	}

	@Test
	public void testDoTables() throws Throwable {
		Parse tables = new Parse(OneLineFixtureUtilsTest
				.wiki2html("|dummy one line|OK|\n\n|dummy one line|OK|"));

		expect(fixtureLoader.disgraceThenLoad("dummy one line")).andReturn(
				new DummyOneLineFixture());
		expect(fixtureLoader.disgraceThenLoad("dummy one line")).andReturn(
				new DummyOneLineFixture());
		replayAll();
		runner.doTables(tables);
		verifyAll();
		String output = listener.getOutput();
		String expected = HTML.replace("</td>\n", "</td>"
				+ SYSTEM_LINE_SEPARATOR);
		assertEquals(expected, output);
	}
}
